/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package muhnes.sizoo.util;

import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.apache.commons.codec.digest.DigestUtils;

/**
 *
 * @author Neotaku
 */
public class Utilidades {
    
    private Utilidades () {
    }
    
    public static String crearFrase( int numeroBytes ) {
        Random random = new Random();
        byte[] fraseBytes = new byte[numeroBytes];
        random.nextBytes(fraseBytes);
        String frase = DigestUtils.md5Hex( fraseBytes );
        return frase;
    }
    
    public static Object obtenerParametro(String jndi) {
        Object parametro = null;
        
        try {
            Context ctx = new InitialContext();
            parametro = (String)ctx.lookup(jndi);
        } catch (NamingException ex) {
            Logger.getLogger( Utilidades.class.getName() ).log( Level.SEVERE,
                                                                null, ex );
        }
        finally {
            return parametro;
        }
    }
    
}
